﻿using System;
using System.Net.Quic;
using System.Runtime.Versioning;
using eLibrary.Environment;

namespace Letter.Net.Quic;

public static class QuicProvider
{
    [RequiresPreviewFeatures]
    public static IQuicClient Client(string name = null)
    {
        if (!(OS.IsLinux() || OS.IsWindows() || OS.IsOSX()))
        {
            throw new NotSupportedException("QUIC is not supported or enabled on this platform. See https://aka.ms/aspnet/kestrel/http3reqs for details.");
        }

        if (!QuicListener.IsSupported)
        {
            throw new NotSupportedException("QUIC is not supported or enabled on this platform. See https://aka.ms/aspnet/kestrel/http3reqs for details.");
        }
        
        return new QuicClient(name);
    }

    [RequiresPreviewFeatures]
    public static IQuicServer Server(string name = null)
    {
        if (!(OS.IsLinux() || OS.IsWindows() || OS.IsOSX()))
        {
            throw new NotSupportedException("QUIC is not supported or enabled on this platform. See https://aka.ms/aspnet/kestrel/http3reqs for details.");
        }
        
        if (!QuicListener.IsSupported)
        {
            throw new NotSupportedException("QUIC is not supported or enabled on this platform. See https://aka.ms/aspnet/kestrel/http3reqs for details.");
        }
        
        return new QuicServer(name);
    }
}